package com.itheima.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
@Aspect // 切面 = 切入点 + 通知
public class TimeAdvice {

    private static  final Logger LOGGER = LoggerFactory.getLogger(TimeAdvice.class);

    @Pointcut("execution(* com.itheima.service.*Service.find*(..))")
    public void pt(){

    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Object result = null;
        long start = System.currentTimeMillis();
        result = pjp.proceed();
        long end = System.currentTimeMillis();
       Signature signature = pjp.getSignature();
//        System.out.println(signature + "->" + (end-start));
        LOGGER.error("{}方法运行时间为{}ms",signature,(end-start));
        return result;
    }
}
